﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MBWebService.Core.Client;
using MBWebService.Core;

namespace MBWebService.Service
{
    public class ClientHelper
    {
        private List<ServiceClient> clients = new List<ServiceClient>();

        public void ConnectToClients()
        {
            if (AppSettings.UserSettings.RemoteComputers.Count > 0)
            {
                // Setup this device
                Server.Proxy.PlaybackDevice device = new Server.Proxy.PlaybackDevice
                {
                    IsMediaCenter = true,
                    IsRemote = true,
                    Name = AppSettings.SessionName
                };

                foreach (var service in AppSettings.UserSettings.RemoteComputers)
                {
                    ServiceClient client = new ServiceClient(service, device);
                    client.ServiceStarted += (o, e) => { MBWebService.Core.Logging.Logger.Instance.LogMessage("Connected to {0}", client.Service); };
                    client.ServiceClosed += (o, e) => { MBWebService.Core.Logging.Logger.Instance.LogMessage("Connection lost to {0}", client.Service); };
                    client.ConnectToService();
                    clients.Add(client);
                }
            }
        }
    }
}
